﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Events.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Modules.peddler.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;
    import L10n.*;

    public class FriendCell extends DataItemCell {

        protected static var s_savedPlayerPic:DisplayObject = null;

        public var m_friend:Friend;
        protected var m_alignmentContainer:JPanel;
        public var m_uid:String;
        protected var m_avatar:DisplayObject;
        protected var m_pic:DisplayObject;
        protected var m_picHasLoaded:Boolean = false;
        protected var m_newFriendLabel:TextField = null;
        protected var m_preload:Boolean = false;
        protected var m_avatarOver:DisplayObject;
        protected var m_holder:Sprite = null;
        private var m_peddlerIcon:DisplayObject;

        public function FriendCell(_arg1:LayoutManager=null){
            super(new FlowLayout(FlowLayout.LEFT, 0));
        }
        override public function setCellValue(_arg1):void{
            this.m_preload = Global.ui.m_friendBar.preload;
            _arg1 = (_arg1 as Object);
            this.m_friend = _arg1;
            this.m_uid = this.m_friend.uid;
            this.buildCell();
            this.addPeddlerIcon();
        }
        public function loadNeighborPortrait():void{
            var _local1:String;
            var _local2:String;
            if (this.m_pic != null){
                return;
            };
            if (((this.m_friend) && (this.m_friend.m_profilePic))){
                _local1 = this.m_friend.m_profilePic;
                if (_local1){
                    if (_local1.substr(0, 4) != "http"){
                        _local2 = Global.getAssetURL(_local1);
                    } else {
                        _local2 = _local1;
                    };
                    if ((((this.m_uid == Global.player.uid)) && (s_savedPlayerPic))){
                        this.m_pic = s_savedPlayerPic;
                    } else {
                        this.m_pic = LoadingManager.loadFromUrl(_local2, {
                            priority:LoadingManager.PRIORITY_LOW,
                            completeCallback:this.onLoadPicSuccess
                        });
                        (this.m_pic as Loader).contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onLoadPicFail, false, 2);
                    };
                    if ((this.m_friend is XPromoFriend)){
                        if (LocaleHelper.localSetting.sns.feature_xpromo){
                            this.m_holder.addChildAt(this.m_pic, this.m_holder.numChildren);
                        } else {
                            this.m_holder.addChildAt(this.m_pic, 1);
                        };
                    } else {
                        this.m_holder.addChildAt(this.m_pic, 1);
                    };
                    this.m_pic.x = 10;
                    this.m_pic.y = 6;
                };
            };
        }
        public function showPic():void{
            if (this.m_pic){
                if (this.m_holder){
                    if ((this.m_friend is XPromoFriend)){
                        this.m_holder.addChildAt(this.m_pic, this.m_holder.numChildren);
                    } else {
                        this.m_holder.addChildAt(this.m_pic, 1);
                    };
                };
            } else {
                this.loadNeighborPortrait();
            };
        }
        protected function buildCell():void{
            var _local1:Number;
            var _local2:AssetPane;
            var _local3:DisplayObject;
            var _local4:JPanel;
            var _local5:JTextField;
            var _local6:String;
            var _local7:DisplayObject;
            var _local8:DisplayObject;
            var _local9:String;
            var _local10:int;
            var _local11:TextFormat;
            var _local12:TextField;
            this.m_alignmentContainer = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -13);
            if (!this.m_friend.empty){
                _local4 = new JPanel(new SoftBoxLayout(SoftBoxLayout.CENTER, 0, 0));
                _local5 = ASwingHelper.makeTextField(this.m_friend.m_name, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.blueTextColor, 0);
                LocaleHelper.localSetting.TextField_adjust(_local5.getTextField(), {
                    embedFonts:false,
                    font:EmbeddedArt.SYSTEM_FONT
                });
                LocaleHelper.localSetting.matchFontAdjust_SIM_HEI(_local5, {
                    topMargin:4,
                    bottomMargin:3,
                    textfield:_local5.getTextField(),
                    size:13
                });
                if ((this.m_friend is XPromoFriend)){
                    _local6 = " ";
                } else {
                    _local6 = this.m_friend.m_name;
                };
                _local4.append(_local5);
                this.m_alignmentContainer.appendAll(ASwingHelper.verticalStrut(-1), _local4);
                this.m_holder = new Sprite();
                if ((this.m_friend is XPromoFriend)){
                    this.m_avatar = (new EmbeddedArt.emptyAvatar() as DisplayObject);
                    _local1 = TextFieldUtil.getLocaleFontSize(10, 8, [{
                        locale:"de",
                        size:12
                    }, {
                        locale:"fr",
                        size:14
                    }, {
                        locale:"es",
                        size:10
                    }]);
                    _local2 = ASwingHelper.makeMultilineText(ZLoc.t("Dialogs", (this.m_friend as XPromoFriend).neighborBarLocKey), 75, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, _local1, 0xFFFFFF, [new GlowFilter(0, 0.5, 3, 3, 10)]);
                    this.m_alignmentContainer.appendAll(ASwingHelper.verticalStrut(70), _local2);
                } else {
                    if (this.m_friend.m_online){
                        this.m_avatar = (new EmbeddedArt.neighborCard_online() as DisplayObject);
                        this.m_avatarOver = (new EmbeddedArt.neighborCard_online_over() as DisplayObject);
                    } else {
                        if (this.m_friend.m_firstTimeVisit){
                            this.m_avatar = (new EmbeddedArt.neighborCard_new() as DisplayObject);
                            this.m_avatarOver = (new EmbeddedArt.neighborCard_new_over() as DisplayObject);
                        } else {
                            this.m_avatar = (new EmbeddedArt.neighborCard() as DisplayObject);
                            this.m_avatarOver = (new EmbeddedArt.neighborCard_over() as DisplayObject);
                        };
                    };
                };
                _local8 = new EmbeddedArt.hud_no_profile_pic();
                this.m_holder.addChildAt(_local8, 0);
                _local8.x = 12;
                _local8.y = 6;
                this.m_holder.addChild(this.m_avatar);
                if (this.m_avatarOver){
                    this.m_holder.addChild(this.m_avatarOver);
                    this.m_avatarOver.visible = false;
                };
                ASwingHelper.setSizedBackground(this.m_alignmentContainer, this.m_holder, new Insets(14, 2, 0, 2));
                this.m_alignmentContainer.append(ASwingHelper.verticalStrut(58));
                if (this.m_friend.m_firstTimeVisit){
                    _local9 = "   ";
                    if (this.m_friend.m_firstTimeVisit){
                        _local9 = ZLoc.t("Main", "NewFriend");
                    };
                    _local10 = 15;
                    if (_local9.length > 4){
                        _local10 = 14;
                        if (_local9.length > 6){
                            _local10 = 12;
                            if (_local9.length > 7){
                                _local10 = 11;
                            };
                        };
                    };
                    _local11 = new TextFormat(EmbeddedArt.TITLE_FONT, _local10, 0xFF6A00, true);
                    _local12 = new TextField();
                    _local12.width = this.m_avatar.width;
                    _local12.wordWrap = false;
                    _local12.multiline = false;
                    _local12.embedFonts = true;
                    _local11.align = TextFormatAlign.CENTER;
                    _local12.text = _local9;
                    _local12.x = 2;
                    _local12.y = 62;
                    _local12.filters = [new GlowFilter(0xFFFFFF, 1, 2, 2, 10), new DropShadowFilter(2, 90, 0, 0.6)];
                    _local12.setTextFormat(_local11);
                    this.m_alignmentContainer.addChild(_local12);
                    this.m_newFriendLabel = _local12;
                };
                if (String(this.m_friend.level) != "-1"){
                    this.generateLevels();
                };
                if ((this.m_friend is XPromoFriend)){
                    this.addEventListener(MouseEvent.CLICK, this.onXPromo, false, 0, true);
                } else {
                    this.addEventListener(MouseEvent.CLICK, this.onClickVisitNeighbor, false, 0, true);
                };
                this.addEventListener(MouseEvent.ROLL_OVER, this.onShowActionButtons, false, 0, true);
                this.addEventListener(MouseEvent.ROLL_OUT, this.onRollOut, false, 0, true);
            } else {
                this.m_avatar = (new EmbeddedArt.emptyAvatar() as DisplayObject);
                ASwingHelper.setSizedBackground(this.m_alignmentContainer, this.m_avatar, new Insets(14));
                if (this.m_preload){
                    this.alpha = 0.6;
                    _local1 = TextFieldUtil.getLocaleFontSize(12, 10, [{
                        locale:"de",
                        size:11
                    }, {
                        locale:"fr",
                        size:12
                    }, {
                        locale:"es",
                        size:11
                    }]);
                    _local2 = ASwingHelper.makeMultilineText(ZLoc.t("Dialogs", "Loading"), 75, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, _local1, 0xFFFFFF, [new GlowFilter(0, 0.5, 3, 3, 10)]);
                    this.m_alignmentContainer.appendAll(ASwingHelper.verticalStrut(88), _local2);
                } else {
                    _local1 = TextFieldUtil.getLocaleFontSize(14, 10, [{
                        locale:"de",
                        size:12
                    }, {
                        locale:"fr",
                        size:14
                    }, {
                        locale:"es",
                        size:12
                    }]);
                    _local2 = ASwingHelper.makeMultilineText(ZLoc.t("Main", "AddFriend"), 75, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, _local1, 0xFFFFFF, [new GlowFilter(0, 0.5, 3, 3, 10)]);
                    this.m_alignmentContainer.appendAll(ASwingHelper.verticalStrut(84), _local2);
                    this.addEventListener(MouseEvent.CLICK, this.onClickAddNeighbor, false, 0, true);
                };
            };
            this.appendAll(ASwingHelper.verticalStrut(15), this.m_alignmentContainer);
            if (this.m_friend.rollCall){
                _local3 = (new EmbeddedArt.payroll_neighborBadge_checkin() as DisplayObject);
                this.addChild(_local3);
                _local3.x = 60;
                _local3.y = 18;
            };
            if (this.m_friend.collect){
                _local3 = (new EmbeddedArt.payroll_neighborBadge_collect() as DisplayObject);
                this.addChild(_local3);
                _local3.x = 55;
                _local3.y = 18;
            };
            ASwingHelper.prepare(this);
        }
        protected function generateLevels():void{
            var _local6:TextField;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, -10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local1.append(ASwingHelper.verticalStrut(22));
            _local2.append(ASwingHelper.horizontalStrut(2));
            _local2.append(ASwingHelper.verticalStrut(34));
            _local1.append(_local2);
            this.m_alignmentContainer.append(_local1);
            var _local3:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, 0xFFFFFF, true);
            var _local4:String = String(this.m_friend.level);
            if (_local4.length == 1){
                _local4 = (" " + _local4);
            };
            var _local5 = 16;
            _local6 = new TextField();
            _local6.multiline = false;
            _local6.wordWrap = false;
            _local6.width = 50;
            _local6.embedFonts = true;
            _local6.text = _local4;
            _local6.setTextFormat(_local3);
            _local6.x = 13;
            _local6.y = _local5;
            _local6.selectable = false;
            _local6.filters = [new DropShadowFilter(2, 90, 0, 0.9)];
            _local2.addChild(_local6);
            var _local7:String = String(this.m_friend.socialLevel);
            if (_local7.length == 1){
                _local7 = (" " + _local7);
            };
            _local6 = new TextField();
            _local6.multiline = false;
            _local6.wordWrap = false;
            _local6.width = 50;
            _local6.embedFonts = true;
            _local6.text = _local7;
            _local6.setTextFormat(_local3);
            _local6.x = 46;
            _local6.y = _local5;
            _local6.selectable = false;
            _local6.filters = [new DropShadowFilter(2, 90, 0, 0.9)];
            _local2.addChild(_local6);
            if (this.m_peddlerIcon == null){
            };
        }
        protected function onLoadPicFail(_arg1:SecurityErrorEvent):void{
            if (!this.m_picHasLoaded){
                _arg1.stopPropagation();
                _arg1.stopImmediatePropagation();
                LoadingManager.cancelLoad(this.m_pic);
                this.m_picHasLoaded = true;
            };
        }
        protected function onLoadPicSuccess(_arg1):void{
            this.m_picHasLoaded = true;
            if (this.m_uid == Global.player.uid){
                s_savedPlayerPic = this.m_pic;
            };
        }
        private function onRollOut(_arg1:MouseEvent):void{
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            if (this.m_avatarOver){
                this.m_avatarOver.visible = false;
                this.m_avatar.visible = true;
            };
        }
        public function onShowActionButtons(_arg1:MouseEvent):void{
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            var _local2:IntPoint = this.getGlobalLocation();
            var _local3:Point = new Point(_local2.x, _local2.y);
            dispatchEvent(new FriendBarSlotEvent(FriendBarSlotEvent.FRIEND_BAR_SLOT_ROLLOVER, this, _local3, "friendbar", "contextual", "friend", true));
            if (this.m_avatarOver){
                this.m_avatarOver.visible = true;
                this.m_avatar.visible = false;
            };
        }
        public function onClickAddNeighbor(_arg1:MouseEvent):void{
            var _local2:IntPoint = this.getGlobalLocation();
            var _local3:Point = new Point(_local2.x, _local2.y);
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            FrameManager.showTray("invite.php?ref=neighbor_ladder");
            StatsManager.sample(100, StatsCounterType.HUD_COUNTER, StatsKingdomType.NEIGHBOR_LADDER, "add_friends");
        }
        public function onXPromo(_arg1:MouseEvent):void{
            StatsManager.sample(100, StatsCounterType.HUD_COUNTER, StatsKingdomType.NEIGHBOR_LADDER, "xpromo", this.m_friend.m_name);
            (this.m_friend as XPromoFriend).onXPromo(_arg1);
        }
        public function onClickVisitNeighbor(_arg1:MouseEvent):void{
            if (Global.disableMenu){
                return;
            };
            var _local2:IntPoint = this.getGlobalLocation();
            var _local3:Point = new Point(_local2.x, _local2.y);
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            dispatchEvent(new FriendBarSlotEvent(FriendBarSlotEvent.FRIEND_BAR_SLOT_CLICK, this, _local3, "friendbar", "contextual", "friend", true));
        }
        public function get uid():String{
            return ((this.m_friend) ? this.m_friend.uid : null);
        }
        public function clearNewFriend():void{
            var _local1:DisplayObjectContainer;
            var _local2:int;
            this.m_friend.m_firstTimeVisit = false;
            if (this.m_newFriendLabel){
                this.m_newFriendLabel.visible = false;
            };
            if (((this.m_avatar) && (this.m_avatar.parent))){
                _local1 = this.m_avatar.parent;
                _local2 = _local1.getChildIndex(this.m_avatar);
                _local1.removeChild(this.m_avatar);
                this.m_avatar = (new EmbeddedArt.neighborCard() as DisplayObject);
                _local1.addChildAt(this.m_avatar, _local2);
            };
            if (((this.m_avatarOver) && (this.m_avatarOver.parent))){
                _local1 = this.m_avatarOver.parent;
                _local2 = _local1.getChildIndex(this.m_avatarOver);
                _local1.removeChild(this.m_avatarOver);
                this.m_avatarOver = (new EmbeddedArt.neighborCard_over() as DisplayObject);
                this.m_avatarOver.visible = false;
                _local1.addChildAt(this.m_avatarOver, _local2);
            };
        }
        public function addPeddlerIcon():void{
            var _local1:PeddlerModel = Global.peddlerManager.hasPlacePeddler(this.uid);
            if (_local1 != null){
                if (((this.m_peddlerIcon) && (this.m_alignmentContainer.contains(this.m_peddlerIcon)))){
                    this.m_peddlerIcon.visible = true;
                } else {
                    this.m_peddlerIcon = (new EmbeddedArt.placePeddler() as DisplayObject);
                    this.m_alignmentContainer.addChild(this.m_peddlerIcon);
                    this.m_peddlerIcon.x = 10;
                    this.m_peddlerIcon.y = 50;
                };
            };
        }
        public function hidePeddlerIcon():void{
            if (((this.m_peddlerIcon) && (this.m_alignmentContainer.contains(this.m_peddlerIcon)))){
                this.m_alignmentContainer.removeChild(this.m_peddlerIcon);
                this.m_peddlerIcon.visible = false;
                this.m_peddlerIcon = null;
            };
        }

    }
}//package Display.NeighborUI 
